//
//  MineTodayNumberVM.swift
//  kxf
//
//  Created by LNS2 on 2024/4/20.
//

import Foundation
import UIKit

class MineTodayNumberVM: UIView {
    
    let selfWidth = kFitWidth(347)
    let selfHeight = kFitWidth(115)
    
    override init(frame:CGRect){
        super.init(frame: CGRect.init(x: kFitWidth(14), y: frame.origin.y, width: selfWidth, height: selfHeight))
        self.backgroundColor = .clear
        self.isUserInteractionEnabled = true
        
        initUI()
    }
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    lazy var bgImgView : UIImageView = {
        let img = UIImageView.init(frame: CGRect.init(x: 0, y: 0, width: selfWidth, height: selfHeight))
//        img.setImgLocal(imgName: "mine_top_item_bg")
        img.isUserInteractionEnabled = true
        img.backgroundColor = .white
        img.layer.cornerRadius = kFitWidth(8)
        img.clipsToBounds = true
        
        return img
    }()
    lazy var titleLab : UILabel = {
        let lab = UILabel()
        lab.textColor = .black
        lab.font = .systemFont(ofSize: 12, weight: .medium)
        lab.text = "今日收款金额（元）"
        return lab
    }()
    lazy var todayMoneyNumberLabel : UILabel = {
        let lab = UILabel()
        lab.font = UIFont().DDInFontBold(fontSize: 40)
        lab.text = "0.0"
        return lab
    }()
    lazy var todayTradeNumLab : UILabel = {
        let lab = UILabel()
        lab.textColor = .black
        lab.font = .systemFont(ofSize: 12, weight: .medium)
        lab.text = "今日交易笔数"
        return lab
    }()
    lazy var todayTradeNumLabel : UILabel = {
        let lab = UILabel()
        lab.font = UIFont().DDInFontBold(fontSize: 20)
        lab.adjustsFontSizeToFitWidth = true
        lab.text = "0"
        return lab
    }()
    lazy var todayPeopleNumbLab : UILabel = {
        let lab = UILabel()
        lab.textColor = .black
        lab.font = .systemFont(ofSize: 12, weight: .medium)
        lab.text = "今日顾客(位)"
        return lab
    }()
    lazy var todayPeopleNumbLabel : UILabel = {
        let lab = UILabel()
        lab.font = UIFont().DDInFontBold(fontSize: 20)
        lab.adjustsFontSizeToFitWidth = true
        lab.text = "0"
        lab.textAlignment = .left
        return lab
    }()
}

extension MineTodayNumberVM{
    func updateUI(dict:NSDictionary) {
        todayMoneyNumberLabel.text = "\(dict["totalAmount"]as? Double ?? 0.00)"
        todayTradeNumLabel.text = "\(dict["tradeCount"]as? Int ?? 0)"
        todayPeopleNumbLabel.text = "\(dict["userNumber"]as? Int ?? 0)"
        
        todayMoneyNumberLabel.textColor = UIColor(patternImage: getGradientImage(size: CGSize.init(width: WHBaseViewVC().getWidthOfString(string: todayMoneyNumberLabel.text ?? "", font: UIFont().DDInFontBold(fontSize: 40), height: kFitWidth(52)), height: kFitWidth(52))))
        todayTradeNumLabel.textColor = UIColor(patternImage: getGradientImage(size: CGSize.init(width: WHBaseViewVC().getWidthOfString(string: todayMoneyNumberLabel.text ?? "", font: UIFont().DDInFontBold(fontSize: 20), height: kFitWidth(52)), height: kFitWidth(52))))
        todayPeopleNumbLabel.textColor = UIColor(patternImage: getGradientImage(size: CGSize.init(width: WHBaseViewVC().getWidthOfString(string: todayMoneyNumberLabel.text ?? "", font: UIFont().DDInFontBold(fontSize: 20), height: kFitWidth(52)), height: kFitWidth(52))))
    }
}
extension MineTodayNumberVM{
    func initUI() {
        addSubview(bgImgView)
        bgImgView.addSubview(titleLab)
        bgImgView.addSubview(todayMoneyNumberLabel)
        bgImgView.addSubview(todayTradeNumLab)
        bgImgView.addSubview(todayTradeNumLabel)
        bgImgView.addSubview(todayPeopleNumbLab)
        bgImgView.addSubview(todayPeopleNumbLabel)
        
//        todayMoneyNumberLabel.frame = CGRect.init(x: kFitWidth(20), y: kFitWidth(27), width: kFitWidth(200), height: kFitWidth(52))
        setConstrait()
        
        ///字体渐变色
        
//        todayMoneyNumberLabel.textColor = UIColor(patternImage: getGradientImage(size: todayMoneyNumberLabel.bounds.size))
        todayMoneyNumberLabel.textColor = UIColor(patternImage: getGradientImage(size: CGSize.init(width: WHBaseViewVC().getWidthOfString(string: todayMoneyNumberLabel.text ?? "", font: UIFont().DDInFontBold(fontSize: 40), height: kFitWidth(52)), height: kFitWidth(52))))
        todayTradeNumLabel.textColor = UIColor(patternImage: getGradientImage(size: CGSize.init(width: WHBaseViewVC().getWidthOfString(string: todayMoneyNumberLabel.text ?? "", font: UIFont().DDInFontBold(fontSize: 20), height: kFitWidth(52)), height: kFitWidth(52))))
        todayPeopleNumbLabel.textColor = UIColor(patternImage: getGradientImage(size: CGSize.init(width: WHBaseViewVC().getWidthOfString(string: todayMoneyNumberLabel.text ?? "", font: UIFont().DDInFontBold(fontSize: 20), height: kFitWidth(52)), height: kFitWidth(52))))
    }
    func setConstrait() {
        titleLab.snp.makeConstraints { make in
            make.left.equalTo(kFitWidth(20))
            make.top.equalTo(kFitWidth(10))
        }
        todayMoneyNumberLabel.snp.makeConstraints { make in
            make.left.equalTo(kFitWidth(20))
            make.top.equalTo(kFitWidth(27))
        }
        todayTradeNumLab.snp.makeConstraints { make in
            make.left.equalTo(kFitWidth(20))
            make.top.equalTo(kFitWidth(86))
        }
        todayTradeNumLabel.snp.makeConstraints { make in
            make.left.equalTo(todayTradeNumLab.snp.right).offset(kFitWidth(5))
            make.centerY.lessThanOrEqualTo(todayTradeNumLab)
            make.width.equalTo(kFitWidth(70))
        }
        todayPeopleNumbLab.snp.makeConstraints { make in
            make.left.equalTo(kFitWidth(176))
            make.centerY.lessThanOrEqualTo(todayTradeNumLab)
        }
        todayPeopleNumbLabel.snp.makeConstraints { make in
            make.right.equalTo(kFitWidth(-20))
            make.left.equalTo(todayPeopleNumbLab.snp.right).offset(kFitWidth(5))
            make.centerY.lessThanOrEqualTo(todayPeopleNumbLab)
        }
    }
}
